package com.atguigu.unsafe;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author sx
 * @date 2022-02-19 11:23
 */
public class MapTest {
    public static void main(String[] args) {
        //工作中不这么用
//        Map<String, String> map = new HashMap<>();

//        Map<String, String> map = Collections.synchronizedMap(new HashMap<>());
        //研究 ConcurrentHashMap 底层实现原理
        Map<String, String> map = new ConcurrentHashMap<>();

        for (int i = 0; i < 30; i++) {
            new Thread(()->{
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0,5));
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
